from alipay.util import image_similarity, calculate_image_similarity

image_path1 = 'screenshots/test/test_3_screenshot.png'
image_path2 = 'screenshots/test/test_2_screenshot.png'
# 比较图片相似度
similarity = calculate_image_similarity(image_path1, image_path2)  # 替换为您的图片路径
print(f'图片相似度 (字节流): {similarity:.4f}')

##########################################################################################
# 示例用法：传入字节流
with open(image_path1, 'rb') as f1:
    image_bytes1 = f1.read()

with open(image_path2, 'rb') as f2:
    image_bytes2 = f2.read()

similarity = calculate_image_similarity(image_bytes1, image_bytes2, is_path=False)
print(f'图片相似度 (字节流): {similarity:.4f}')
